package com.canyou.exception;

import com.canyou.api.IErrorCode;
import com.canyou.utils.StringUtils;
import lombok.Getter;

/**
 * 自定义运行时异常,业务异常
 *
 * @author fuyong
 * @date 2017-05-16
 */
@Getter
public class CysBusinessException extends RuntimeException implements IErrorCode {

    private static final long serialVersionUID = -908802729181803207L;

    /**
     * 错误码
     */
    private Integer code;
    /**
     * 错误提示
     */
    private String msg;


    public CysBusinessException(IErrorCode errorCodeEnum) {
        super(errorCodeEnum.getMsg());
        this.code = errorCodeEnum.getCode();
    }

    public CysBusinessException(IErrorCode errorCodeEnum, Throwable cause) {
        super(errorCodeEnum.getMsg(), cause);
        this.code = errorCodeEnum.getCode();
    }

    public CysBusinessException(IErrorCode errorCodeEnum, String msg) {
        super(StringUtils.isNotBlank(msg) ? msg : errorCodeEnum.getMsg());
        this.code = errorCodeEnum.getCode();
        this.msg = msg;
    }

    public CysBusinessException(IErrorCode errorCodeEnum, String msg, Throwable cause) {
        super(StringUtils.isNotBlank(msg) ? msg : errorCodeEnum.getMsg(), cause);
        this.code = errorCodeEnum.getCode();
        this.msg = msg;
    }

    public CysBusinessException(Integer code, String msg) {
        super(msg);
        this.code = code;
    }

    @Override
    public String getMsg() {
        return getMessage();
    }
}
